package model;

import java.util.ArrayList;
import java.util.List;

import common.DataManager;
import common.GridCoordinate;


/**
 * @author Colin
 *
 *The small laser has a cost of 200, a single grid straight line 
 *range of 5x1, a rate of 3, damage of 1 and speed of 1.
 */
public class SmallLaser extends AutomaticWeapon{
	
	private static final int DEFAULT_COST = 500;
	private static final int DEFAULT_DAMAGE = 1;
	private static final int DEFAULT_SPEED = 10;
	private static final int DEFAULT_RANGE_INT = 5;
	private static final int DEFAULT_RATE = 1;
	
	private double angle = 0;
	
	//SmallLaser without position
	public SmallLaser(){
		super( "Laser", DataManager.SMALL_LASER, DataManager.SMALL_LASER_AMMO, DEFAULT_COST, DEFAULT_DAMAGE, DEFAULT_SPEED, DEFAULT_RANGE_INT, DEFAULT_RATE );
		
	}
	
	//SmallLaser with position
	public SmallLaser( GridCoordinate position ){
		super( "Laser", DataManager.SMALL_LASER, DataManager.SMALL_LASER_AMMO, DEFAULT_COST, position, DEFAULT_DAMAGE, DEFAULT_SPEED, DEFAULT_RANGE_INT, DEFAULT_RATE );
		
		createRange();
	}

	/**
	 * Rotates the straight range 90 degrees by using the length of
	 * the range and cos and sin of 90 deg.
	 * 
	 * @see model.AutomaticWeapon#rotateCCW()
	 */
	@Override
	public void rotateCCW(){
		int curRangeInt = getRangeInt();
		List<GridCoordinate> newRange = new ArrayList<GridCoordinate>();
		angle = ((angle - Math.PI/2));
		for(int i = 1; i <= curRangeInt; ++i ){
			GridCoordinate newPos = new GridCoordinate((getPosition().getX() + (int)(i * Math.cos(angle))), (getPosition().getY() + (int)(i * Math.sin(angle))));
			newRange.add( newPos );
		}
		setRange( newRange );
		this.setRotation((int)((angle*180/Math.PI))%360);
		System.out.println(this.getRotation());
	}

	@Override
	public void createRange() {
		List<GridCoordinate> range = new ArrayList<GridCoordinate>();
		
		//Sets straight line range of 5x1
		for( int i = 1; i <= getRangeInt(); ++i ){
			range.add( new GridCoordinate( getPosition().getX() + i, getPosition().getY()));
		}
		setRange( range );
		
	}

	@Override
	public String getDescription() {
		return "The Laser fires on any zombosaurs in the 5 tiles in front of it. Clicking on the turret while in setup mode rotates it.";
	}
	

}
